//
//  WmcEditPhotoCompleteView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/19.
//

import UIKit

class WmcEditPhotoCompleteView: WmcBaseView {
    lazy var maskLayer: CAShapeLayer = {
        let maskLayer = CAShapeLayer()
        return maskLayer
    }()
    
    lazy var stackView: UIStackView = {
        let stackView = UIStackView(arrangedSubviews: [
//            uploadBtn,
            wechatFriendBtn,
            wechatCycleBtn
        ])
        stackView.axis = .horizontal
        stackView.distribution = .equalSpacing
        stackView.alignment = .fill
        stackView.spacing = 30
        return stackView
    }()
    
    lazy var wechatCycleBtn: WmcTopImgBottomTextBtn = {
        let btn = CreateBtn(title: "朋友圈", image: "friends_circle_color".wmc_image)
        return btn
    }()
    
    lazy var wechatFriendBtn: WmcTopImgBottomTextBtn = {
        let btn = CreateBtn(title: "微信", image: "wechat_icon_color".wmc_image)
        return btn
    }()
    
    lazy var uploadBtn: WmcTopImgBottomTextBtn = {
        let btn = CreateBtn(title: "上传至项目", image: "edit_upload_project".wmc_image)
        return btn
    }()
    
    lazy var completeBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .wmc_mainTheme
        btn.setTitle("完成", for: .normal)
        btn.setTitleColor(UIColor.white, for: .normal)
        btn.titleLabel?.font = 16.wmc_font
        btn.layer.cornerRadius = 4
        btn.layer.masksToBounds = true
        return btn
    }()
    
    lazy var resetEditBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .clear
        btn.setTitle("重新编辑", for: .normal)
        btn.setTitleColor(UIColor.wmc_mainTheme, for: .normal)
        btn.titleLabel?.font = 16.yp.uiFont(weight: .medium)
        btn.yp.addEvent { [weak self] _ in
            guard let weakSelf = self else { return }
            weakSelf.presentVC?.dismiss(animated: true, completion: nil)
        }
        return btn
    }()
    
    func CreateBtn(title: String, image: UIImage) -> WmcTopImgBottomTextBtn {
        let btn = WmcTopImgBottomTextBtn(title: title, image: image)
        btn.font = 14.yp.uiFont(weight: .medium)
        btn.imgTextSpacing = 6
        btn.imgSize = 32
        btn.textColor = .wmc_grayH2_323233
        btn.yp.layoutWidthEqual(70.wmc_autoHor)
        return btn
    }
    
    var presentVC: UIViewController?
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let maskPath = UIBezierPath(roundedRect: bounds,
                                    byRoundingCorners: [.topLeft, .topRight],
                                    cornerRadii: 8.yp.cgSize)
        maskLayer.path = maskPath.cgPath
        maskLayer.frame = bounds
        layer.mask = maskLayer
    }

    override func makeUI() {
        
        addSubview(stackView)
        stackView.snp.makeConstraints { make in
            make.top.equalTo(24)
            make.height.equalTo(60)
            make.left.equalTo(50)
            make.right.equalTo(-50)
        }
        
        addSubview(completeBtn)
        completeBtn.snp.makeConstraints { make in
            make.top.equalTo(stackView.snp.bottom).offset(24)
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(-Wmc_standardEdge.right)
            make.height.equalTo(44)
        }
        
        addSubview(resetEditBtn)
        resetEditBtn.snp.makeConstraints { make in
            make.top.equalTo(completeBtn.snp.bottom)
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(-Wmc_standardEdge.right)
            make.height.equalTo(50)
        }
    }
}
